package com.wuji.salary.controller;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiV2UserUpdateRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiV2UserUpdateResponse;
import com.taobao.api.ApiException;
import com.wuji.salary.entity.Algorithm;
import com.wuji.salary.entity.R;
import com.wuji.salary.service.AlgorithmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * (Algorithm)表控制层
 *
 * @author makejava
 * @since 2024-07-27 10:43:11
 */
@RestController
@RequestMapping("/algorithm")
public class AlgorithmController {

    /**
     * 服务对象
     */
    @Autowired
    private AlgorithmService algorithmService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list/page")
    public R queryByPage() {
        return R.ok(this.algorithmService.queryByPage());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R queryById(@PathVariable("id") Integer id) {
        return R.ok(this.algorithmService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param algorithm 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public R add(@RequestBody Algorithm algorithm) {
        return this.algorithmService.insert(algorithm);
    }

    /**
     * 编辑数据
     *
     * @param algorithm 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R edit(@RequestBody Algorithm algorithm) {
        this.algorithmService.update(algorithm);
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param algorithmName 算法名
     * @return 删除是否成功
     */
    @GetMapping("/del")
    public R deleteById(String algorithmName) {
        this.algorithmService.deleteById(algorithmName);
        return R.ok();
    }

}

